package com.hl.sfzy.controller;

import com.hl.sfzy.constant.CommonConstant;
import com.hl.sfzy.constant.Result;

import com.hl.sfzy.entity.SysMessage;

import com.hl.sfzy.entity.SysEvaluate;
import com.hl.sfzy.entity.SysMessage;
import com.hl.sfzy.entity.SysUser;
import com.hl.sfzy.service.SysEvaluateService;

import com.hl.sfzy.service.SysMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
public class sysMessageController {
    @Autowired
    private SysMessageService sysMessageService;

    @PostMapping("/message")
    public Result add(@RequestBody SysMessage sysMessage) {
        int num = sysMessageService.add(sysMessage);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/message/{id}")
    public Result remove(@PathVariable("id") Integer id) {
        int num = sysMessageService.remove(id);
        return num > 0 ? Result.success() : Result.error();
    }

    @DeleteMapping("/message")
    public Result removeBatch(Integer[] ids) {
        int num = sysMessageService.removeBatch(ids);
        return num > 0 ? Result.success() : Result.error();
    }
    @PutMapping("/message/put")
    public Result edit(@RequestBody SysMessage sysMessage){
        int num = sysMessageService.edit(sysMessage);
        return num > 0 ? Result.success() : Result.error();
    }

    @GetMapping("/message/page")
    public Result findPage(
            @RequestParam(value = CommonConstant.PAGE_NUM, required = false, defaultValue = CommonConstant.PAGE_NUM_DEFAULT) Integer pageNum,
            @RequestParam(value = CommonConstant.PAGE_SIZE, required = false, defaultValue = CommonConstant.PAGE_SIZE_DEFAULT) Integer pageSize,
            SysMessage sysMessage ) {

        Map<String, Object> map = sysMessageService.findPage(pageNum, pageSize, sysMessage);
        return Result.success(map);
    }
    @GetMapping("/message")
    public Result findAll( SysMessage sysMessage){
        List<SysMessage> sysMessages = sysMessageService.find(sysMessage);
        return Result.success(sysMessages);
    }

    @GetMapping("/message/{id}")
    public Result findById(@PathVariable("id") Integer id){
        SysMessage byId = sysMessageService.findById(id);
        return Result.success(byId);
    }

    @GetMapping("/message/consult/{id}")
    public Result findByconsultId(@PathVariable("id") Integer id){
        List<SysMessage> byConsultId = sysMessageService.findByConsultId(id);
        return Result.success(byConsultId);
    }

    @GetMapping("/message/limit/{id}")
    public Result findLimit(@PathVariable("id") Integer id){
        List<SysMessage> byConsultId = sysMessageService.findLimit(id);
        return Result.success(byConsultId);
    }

}
